#ifndef _USER_PROTOCOL_H_
#define _USER_PROTOCOL_H_

/*******************************************************************
 *
 * Copyright (C), 2021-2022, Letstrong, All rights reserved.
 *
 * Author      : 
 * Create Time : 2020-12-18
 * Version     : v0.1
 * Description : 
 *******************************************************************/
 
/*----------------------------Head file----------------------------*/
#include "stdint.h"
#include "stdbool.h"

/*----------------------------macro file---------------------------*/
#define USER_PROTO_SUCCESS		0

#define DEV_MAC_INVALID			0
#define DEV_MAC_VALID			1

#define APP_PACKET_HEAD_SIZE				7
#define APP_FIRST_FRAME_DATA_MAX_SIZE		13
#define APP_REST_FRAME_DATA_MAX_SIZE		19

#define	OFFSETOF(type, member)	((unsigned int)&((type *)0)->member) 

#define BUILD_UINT16(loByte, hiByte) \
          ((uint16_t)(((loByte) & 0x00FF) + (((hiByte) & 0x00FF) << 8)))

#define BUILD_UINT32(Byte0, Byte1, Byte2, Byte3) \
          ((uint32_t)((uint32_t)((Byte0) & 0x00FF) \
          + ((uint32_t)((Byte1) & 0x00FF) << 8) \
          + ((uint32_t)((Byte2) & 0x00FF) << 16) \
          + ((uint32_t)((Byte3) & 0x00FF) << 24)))

/*----------------------------type define--------------------------*/

typedef enum {
	SKIP_CMD_REST_DATA    = 0,
	SKIP_CMD_DISP_DATA    = 0x01,
	SKIP_CMD_REALTIME_RET = 0x02,
	SKIP_CMD_HISTORY_RET  = 0x03,
	
	SKIP_CMD_SYNC_TIME    = 0x80,
	SKIP_CMD_START_SKIP   = 0x81,
	SKIP_CMD_STOP_SKIP    = 0x82,
	SKIP_CMD_SEARCH_DEV   = 0x83,
	
	SKIP_CMD_DEV_RESET    = 0xF7,
	SKIP_CMD_DEV_REVERT   = 0xF8,
	SKIP_CMD_SET_ADV_NAME = 0xF9,
	SKIP_CMD_GO_BURN_MODE = 0xFA,
	SKIP_CMD_BURN_MAC     = 0xFB,
	SKIP_CMD_CHECK_BURN   = 0xFC,
	SKIP_CMD_FAC_TEST     = 0xFD,
	SKIP_CMD_BURN_DEV_SEQ = 0xFE,
	SKIP_CMD_UNKNOW       = 0xFF
} user_cmd_t;

#pragma pack(1)
typedef struct {
	uint8_t mode;
	uint16_t setting;
	uint16_t skip_sec_sum;
	uint16_t skip_cnt_sum;
	uint8_t trip_num;
	uint8_t batt_per;
	uint16_t skip_valid_sec;
}user_skip_disp_data_t;

typedef struct {
	uint32_t utc;
	uint16_t timezone_mins;
}user_sync_time_t;

typedef struct {
	uint8_t mode;
	uint16_t setting;
	uint32_t utc;
	uint16_t cnt_down_start;
}user_start_skip_t;
#pragma pack()

/*----------------------------var define---------------------------*/

/*-------------------------func declaration------------------------*/
extern bool user_muti_indicate_trans_done(void);

extern void app_skip_mem_delay_send_timer_start(void);
extern void app_skip_mem_delay_send_timeout_handle(void);
extern void app_skip_mem_resend_timeout_handle(void);
extern void app_skip_mem_resend_timer_start(void);
extern void user_upload_info_to_app_process(uint8_t cmd);
extern bool user_upload_unsent_skip_data(bool increase);
extern void ble_rope_client_write_rsp(const uint8_t* data, uint16_t len);

/*-----------------------------------------------------------------*/

#endif
